package com.tcredit.spider.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration//@Configuration注解，表明它是一个配置类
@EnableSwagger2//@EnableSwagger2开启swagger2
public class Swagger2 {

	@Bean
	public Docket createRestApi() {
		//apis()指定扫描的包会生成文档
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.tcredit.spider.web.controller")).paths(PathSelectors.any()).build();
	}

	//apiINfo()配置一些基本的信息
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("SpringBoot利用Swagger构建API文档")
				.description("简单优雅的restfun风格")
				.termsOfServiceUrl("https://www.baidu.com").version("1.0").build();
	}
}
